package com.qf.controller;

import com.qf.pojo.User;
import com.qf.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.test.annotation.Repeat;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * projectName: wokepase1
 *
 * @author: 强力
 * time: 2021/9/2 20:55
 * description:
 */
@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/userlist")
    public String findAll(Model mav){
//        PageHelper.startPage(1,3);
        List<User> userlist = userService.findAll();
//        PageInfo<User> pageInfo=new PageInfo<>(userlist);
        mav.addAttribute("userlist",userlist);
        return "userlist";
    }

    @RequestMapping("/insert")
    @ResponseBody
    public int insert(@RequestBody User user) {

        int i = userService.insertUser(user);

        return i;
    }

    @RequestMapping("/update")
    @ResponseBody
    public int update(@RequestBody User user){


        int i = userService.updateUser(user);

        return i;
    }

    @RequestMapping("/delect")
    public String delect(int id){
        userService.delectUser(id);

        return "redirect:/user/userlist";
    }
}
